package com.shangxian.giveithome.controller;

import com.shangxian.giveithome.annoaction.CheckLoginStatus;
import com.shangxian.giveithome.code.CommonCode;
import com.shangxian.giveithome.entity.petCard.inputParam.*;
import com.shangxian.giveithome.result.Result;
import com.shangxian.giveithome.service.PetCardQrService;
import com.shangxian.giveithome.service.PetCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author coderFu
 * @create 2021/4/25
 *
 */
@RestController
@Api(tags = "宠牌模块")
@RequestMapping("/petCard")
public class PetCardController {

    @Autowired
    private PetCardService petCardService;

    @Resource
    private HttpServletRequest request;

    @Autowired
    private PetCardQrService petCardQrService;

    @PostMapping("/findPetMessage")
    @ApiOperation("查询二维码详情信息")
    @CheckLoginStatus
    public Result findPetMessage(@RequestParam("id") Long id, @RequestBody Address address){
        return Result.success(petCardService.findPetMessage(id,request,address));
    }

    @PostMapping("/bandingPetMessage")
    @ApiOperation("绑定宠物信息")
    @CheckLoginStatus
    public Result bandingPetMessage(@RequestBody BandingPetMessage bandingPetMessage ){
        petCardService.bandingPetMessage(bandingPetMessage,request);
        return Result.success();
    }

    @GetMapping("/findPetMessageById")
    @ApiOperation("根据宠牌表记录id查询宠物用户信息")
    @CheckLoginStatus
    public Result findPetMessageById(@RequestParam("id") Long id){
        return Result.success(petCardService.findPetMessageById(id));
    }

    @PostMapping("/recordInoculationMessage")
    @ApiOperation("记录接种信息")
    @CheckLoginStatus
    public Result recordInoculationMessage(@RequestBody VaccinesMessageParam vaccinesMessageParam ){
        petCardService.recordInoculationMessage(vaccinesMessageParam,request);
        return Result.success();
    }

    @GetMapping("/findActionRecord")
    @ApiOperation("查询行动记录详情")
    @CheckLoginStatus
    public Result findActionRecord(@RequestParam("id") Long id, @PageableDefault(page = 0,size = 10) Pageable pageable){
         return Result.success(petCardService.findActionRecord(id,pageable));
    }

    @GetMapping("/findInoculationRecord")
    @ApiOperation("查询接种记录")
    @CheckLoginStatus
    public Result findInoculationRecord(@RequestParam("id") Long id){
        return Result.success(petCardService.findInoculationRecord(id));
    }

    @GetMapping("/findMyPetCardMessages")
    @ApiOperation("查询所有宠牌信息")
    @CheckLoginStatus
    public Result findMyPetCardMessages(){
        return Result.success(petCardService.findMyPetCardMessages(request));
    }

    @PostMapping("/updatePetCardMessage")
    @ApiOperation("修改宠牌绑定的宠物信息")
    @CheckLoginStatus
    public Result updatePetCardMessage(@RequestBody BandingPetMessage bandingPetMessage){
        petCardService.updatePetCardMessage(bandingPetMessage);
        return Result.success();
    }

    @PostMapping("/produceOneQr")
    @ApiOperation("按顺序生成一张宠牌二维码")
    public Result produceOneQr(){
        petCardQrService.produceOneQr();
        return Result.success();
    }

    @GetMapping("/findPetQrCodePathById")
    @ApiOperation("根据二维码id查询二维码路径")
    public Result findPetQrCodePathById(@RequestParam("id") Long id){
        return Result.success(petCardService.findPetQrCodePathById(id));
    }



    @PostMapping("/produceHundredQr")
    @ApiOperation("按顺序生成一百张宠牌二维码")
    public Result produceHundredQr(){
        petCardQrService.produceHundredQr();
        return Result.success();
    }

    @GetMapping("/findAllCardQr")
    @ApiOperation("查看所有二维码")
    public Result findAllPetCardQr(@PageableDefault(page = 0,size = 10) Pageable pageable, @RequestParam(value = "petCardNo",required = false)String petCardNo){
        return Result.success(petCardQrService.findAllPetCardQr(pageable,petCardNo));
    }

    @DeleteMapping("/deletePetCardQrById")
    @ApiOperation("删除二维码")
    public Result deletePetCardQrById(@RequestParam("id") Long  id){
        petCardQrService.deletePetCardQrById(id);
        return Result.success();
    }

    @GetMapping("/findPetCardDetailsByQrId")
    @ApiOperation("通过二维码id查询宠物详情接口")
    public Result findPetCardDetailsByQrId(@RequestParam("id") Long id){
        return Result.success(petCardService.findPetCardDetailsByQrId(id));
    }

    @GetMapping("/backFindPetCardList")
    @ApiOperation("后台查询宠物主人信息表/宠牌列表")
    public Result backFindPetCardList(@PageableDefault(page = 0,size = 10) Pageable pageable,BackSearchParam backSearchParam ){
        return Result.success(petCardService.backFindPetCardList(pageable,backSearchParam));
    }

    @GetMapping("/backFindPetCardDetails")
    @ApiOperation("后台根据宠牌表id查询宠物详细信息")
    public Result backFindPetCardDetails(@RequestParam("id") Long id){
        return Result.success(petCardService.backFindPetCardDetailsById(id));
    }

    @PostMapping("/backUpdatePetCardMessage")
    @ApiOperation("后台根据宠牌表id修改宠物信息")
    public Result backUpdatePetCardMessage(@RequestBody BackUpdatePetCardParam backUpdatePetCardParam){
        petCardService.backUpdatePetCardMessage(backUpdatePetCardParam);
        return  Result.success(CommonCode.UPDATE_SUCCESS);
    }

    @PostMapping("/backMakePetCert")
    @ApiOperation("后台录入主人身份证信息和宠牌表id制作宠物证书")
    public Result backMakePetCert(@RequestParam("id") Long id, @RequestParam("identityId") String identityId){
        petCardService.backMakePetCert(id,identityId);
        return Result.success();
    }

    @GetMapping("/backFindVaccinesRecordByPetCardCodeId")
    @ApiOperation("后台根据宠牌编号查询宠物接种记录")
    public Result backFindVaccinesRecord(@RequestParam("petCardNo") String petCardNo){
        Long petCardCodeId = Long.parseLong(petCardNo);
        return Result.success(petCardService.backFindVaccinesRecordByPetCardCodeId(petCardCodeId));
    }

    @PostMapping("/backAddVaccines")
    @ApiOperation("后台添加宠物疫苗")
    public Result backAddVaccines(@RequestBody BackAddVaccinesParam backAddVaccinesParam){
        petCardService.backAddVaccines(backAddVaccinesParam);
        return Result.success();
    }

//    @PostMapping("/backForbiddenPetCardById")
//    @ApiOperation("后台根据宠牌表id禁用该宠牌")
//    public Result backForbiddenPetCardById(@RequestParam("id") Long id){
//        petCardService.backForbiddenPetCardById(id);
//    }
}
